

#import "PUPerfectVC.h"
#import "BRDatePickerView.h"
#import "PUTipView.h"
#import "MSCTakePictureViewController.h"
#import "IQKeyboardManager.h"
#import "IQKeyboardReturnKeyHandler.h"
//#import "CPChangePhoneNumVC.h"
#import "appDelegate.h"

@interface PUPerfectVC ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,CPTipViewDelegate,UIGestureRecognizerDelegate>{
    NSString * uploadFilePath;
    int originConstraintValue;
}
@property(nonatomic,retain)UIImageView *touImage;
@property(nonatomic,retain)UIButton *boyBtn;
@property(nonatomic,retain)UIButton *girlBtn;
@property(nonatomic,retain)UIButton *submitBtn;
@property(nonatomic,strong)UITextField *nickNameField;
@property(nonatomic,strong)UITextField *yaoqingTF;
@property(nonatomic,retain)UIButton *suijiNameBtn;
@property(nonatomic,retain)UILabel *birthLab;
@property(nonatomic,retain)NSString *birthStr;
@property(nonatomic,retain)NSData *imageData;
@property(nonatomic)int sex;
@property(nonatomic,retain)NSString *yaoqingStr;
@property(nonatomic,retain)NSString *touImageStr;
@property(nonatomic,retain)NSDate *birthdaySelectDate;

@property(nonatomic,retain)NSString *boyNickName;
@property(nonatomic,retain)NSString *boyBirth;
@property(nonatomic,retain)NSData *boyImageData;
@property(nonatomic,retain)UIImage *boyImage;
@property(nonatomic,retain)NSString *girlNickName;
@property(nonatomic,retain)NSString *girlBirth;
@property(nonatomic,retain)NSData *girlImageData;
@property(nonatomic,retain)UIImage *girlImage;
@property(nonatomic,retain)NSString *boyuploadFilePath;
@property(nonatomic,retain)NSString *girluploadFilePath;
@property(nonatomic,retain)NSString *boyupfileName;
@property(nonatomic,retain)NSString *girlupfileName;


@property(nonatomic,retain)NSString *boyuploadImageUrl;
@property(nonatomic,retain)NSString *girluploadImageUrl;

//@property (nonatomic, copy) Checkpoint *checkpoint;
@property (nonatomic, copy) NSString *downloadURLString;
@property (nonatomic, copy) NSString *headURLString;
@property (nonatomic)BOOL isCanSideBack;
@property (nonatomic)int tipViewType;//1----点击了返回键，不执行下一步 2----点击了提交，调完善资料的接口

@end

@implementation PUPerfectVC
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self forbiddenSideBack];
}
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [self resetSideBack];
    
    //    [[NSNotificationCenter defaultCenter] postNotificationName:@"closeGroupTimerNSNotification2" object:self userInfo:nil];//关闭跑马灯定时器
    //    NSLog(@"after---%@",[NSThread currentThread]);  // 打印当前线程
}
/**
 * 禁用边缘返回
 */
-(void)forbiddenSideBack{
    self.isCanSideBack = NO;
    //关闭ios右滑返回
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.delegate=self;
    }
}

/*
 恢复边缘返回041qEAll2fUNHd4CP4ml2DOt7m1qEAlw
 */
- (void)resetSideBack {
    self.isCanSideBack=YES;
    //开启ios右滑返回
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.delegate = nil;
    }
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {
    return self.isCanSideBack;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    self.birthStr=@"";
    self.boyuploadFilePath=@"";
    self.girluploadFilePath=@"";
    self.boyuploadImageUrl=@"";
    self.girluploadImageUrl=@"";
    self.sex=1;
    
    self.boyupfileName=@"";
    self.girlupfileName=@"";
    
    
    NSDate *now = [NSDate date];
    NSLog(@"当前时间: %@", now);
        
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
     
    NSInteger year = [dateComponent year];
    NSInteger month = [dateComponent month];
    NSInteger day = [dateComponent day];
//    int hour = [dateComponent hour];
//    int minute = [dateComponent minute];
//    int second = [dateComponent second];
 
    NSLog(@"年---%ld",(long)year);
    NSLog(@"月---%ld",(long)month);
    NSLog(@"日---%ld",(long)day);
    
    NSString *monthformattedString = @"";
    NSString *dayformattedString = @"";
    
    if (month >= 1 && month <= 9) {
        
        monthformattedString = [NSString stringWithFormat:@"%02ld", (long)month];
        NSLog(@"%@", monthformattedString);
    }else{
        monthformattedString=[NSString stringWithFormat:@"%ld",(long)month];
    }
    if (day >= 1 && day <= 9) {
        dayformattedString = [NSString stringWithFormat:@"%02ld", (long)day];
        NSLog(@"%@", dayformattedString);
    }else{
        dayformattedString=[NSString stringWithFormat:@"%ld",(long)day];
    }


    NSInteger y=year-22;
    NSString *str1=[NSString stringWithFormat:@"%ld-%@-%@",(long)y,monthformattedString,dayformattedString];
//    self.boyBirth=str1;
//    self.birthStr=str1;
    
    
    NSString* dateStr = str1;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd";
    NSDate *date = [dateFormatter dateFromString:dateStr];
    NSLog(@"date=%@", date);
    self.birthdaySelectDate=date;
    
    [self addView];
    
    [self loadRandNickname];
    
//    [self loadputImageToken];
    
    //禁用IQKeyboardManager
    IQKeyboardManager *keyboardManager =  [IQKeyboardManager sharedManager];
    keyboardManager.enable = YES;
    keyboardManager.enableAutoToolbar = YES;
    
//    [self pushBDSJ];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PerfectChangeBtnBackground) name:UITextFieldTextDidChangeNotification object:nil];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)boyViewGesture{
    self.sex=1;
    self.boyImageView.layer.borderWidth = 2;
    self.boyLab.textColor=[UIColor colorWithHex:0x2B56FB];
    
    self.girlImageView.layer.borderWidth = 0;
    self.girlLab.textColor=[UIColor colorWithHex:0x999999];
    
    self.suijiNameBtn.hidden=NO;
    
    if(self.boyImage==nil){
        self.touImage.image=[UIImage imageNamed:@"manHead"];
    }else{
        self.touImage.image=self.boyImage;
    }
   
    if(![self.boyBirth isEqualToString:@"选择生日"]&&self.boyBirth!=nil){
        self.birthLab.text=self.boyBirth;
        self.birthLab.textColor=[UIColor blackColor];
    }else{
        self.birthLab.text=@"选择生日";
        self.birthLab.textColor=[UIColor colorWithHex:0xD1D4D8];
    }
    
    self.nickNameField.text=self.boyNickName;
    self.imageData=self.boyImageData;
    
    
    [self PerfectChangeBtnBackground];
}
-(void)girlViewGesture{
    self.sex=0;
    self.boyImageView.layer.borderWidth = 0;
    self.boyLab.textColor=[UIColor colorWithHex:0x999999];
    
    self.girlImageView.layer.borderWidth = 2;
    self.girlLab.textColor=[UIColor colorWithHex:0xFF729A];
    
    self.sex=0;
    self.suijiNameBtn.hidden=YES;
    if(self.girlImage==nil){
        self.touImage.image=[UIImage imageNamed:@"upImage"];
    }else{
        self.touImage.image=self.girlImage;
    }
    
    
    if(![self.girlBirth isEqualToString:@"选择生日"]&&self.girlBirth!=nil){
        self.birthLab.text=self.girlBirth;
        self.birthLab.textColor=[UIColor blackColor];
    }else{
        self.birthLab.text=@"选择生日";
        self.birthLab.textColor=[UIColor colorWithHex:0xD1D4D8];
    }
    self.nickNameField.text=self.girlNickName;
    self.imageData=self.girlImageData;
    
    [self PerfectChangeBtnBackground];
}
-(void)addView{
    
//    UIImageView *rightImage=[[UIImageView alloc]init];
//    rightImage.frame=CGRectMake(0,0,_window_width,_window_width*0.410);
//    rightImage.image=[UIImage imageNamed:@"alphaImage"];
//    [self.view addSubview:rightImage];
    
    
    UIView *butV = [[UIView alloc] initWithFrame:CGRectMake(_window_width*0.042, _window_width*0.128, 40, 40)];
    [self.view addSubview:butV];
    UIImageView *imV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    imV.image = [UIImage imageNamed:@"backBtn"];
    [butV addSubview:imV];
    
    
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 40, 40);
    [butV addSubview:leftButton];
    [leftButton addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [butV addSubview:leftButton];
    
    CGFloat x=_window_width*0.128+40;
    
    UILabel *numLab=[[UILabel alloc]init];
    numLab.frame = CGRectMake(x, _window_width*0.12, _window_width-2*x,_window_width*0.07);
    numLab.text=@"基本信息";
    numLab.textAlignment=NSTextAlignmentCenter;
    numLab.font=[UIFont systemFontOfSize:21];
    [self.view addSubview:numLab];
    
    UILabel *jbzlLab=[[UILabel alloc]init];
    jbzlLab.frame = CGRectMake(x, numLab.frame.origin.y+numLab.frame.size.height+16*KWidthScale, _window_width-2*x,34*KWidthScale);
    jbzlLab.text=@"填写基本资料";
    jbzlLab.textAlignment=NSTextAlignmentCenter;
    jbzlLab.font=[UIFont systemFontOfSize:28];
    [self.view addSubview:jbzlLab];
    
    YYLabel *yyCZLabel = [[YYLabel alloc]initWithFrame:CGRectMake(0,jbzlLab.frame.origin.y+jbzlLab.frame.size.height+8*KWidthScale,_window_width,20*KWidthScale)];
    yyCZLabel.font=[UIFont systemFontOfSize:18];
    yyCZLabel.numberOfLines=0;
    [self.view addSubview:yyCZLabel];
//        [self protocolIsSelect:NO];
//    yyCZLabel.backgroundColor=[UIColor blueColor];
    int online=0;
    NSDictionary *saveSystemConfig = [Config getOpenAppConfig];
    if (saveSystemConfig!=nil) {
        online=[saveSystemConfig[@"online"] intValue];
    }
    
    NSString *name=[NSString stringWithFormat:@"%d",online];
    NSString *conten=[NSString stringWithFormat:@"有%@位用户在线登录后可见",name];
//    NSString *s1=@"且代表你已成年，若遇到问题，请联系";
//    NSString *s2=@"在线客服";
    NSString *str=conten;
    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName: [UIColor colorWithHex:0x999999]};
    NSMutableAttributedString *yyCZtext = [[NSMutableAttributedString alloc] initWithString:str attributes:attributes];
    
//    [yyCZtext addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:24] range:[[yyCZtext string] rangeOfString:name]];
    //设置高亮色和点击事件
    [yyCZtext yy_setTextHighlightRange:[[yyCZtext string] rangeOfString:name] color:[UIColor colorWithHex:0xFF729A] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        NSLog(@"《用户充值协议》");
    }];
    
    yyCZLabel.attributedText = yyCZtext;
    yyCZLabel.textAlignment = NSTextAlignmentCenter;
    yyCZLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    
    
    
    
//    UIImageView *touImage=[[UIImageView alloc]init];
//    touImage.frame=CGRectMake(_window_width*0.378, _window_width*0.272, _window_width*0.24, _window_width*0.24);
//    touImage.image=[UIImage imageNamed:@"manHead"];
//    touImage.layer.masksToBounds = YES;
//    touImage.layer.cornerRadius = touImage.frame.size.height/2;
//    [self.view addSubview:touImage];
////    [touImage sd_setImageWithURL:[NSURL URLWithString:@"https://huayuoss-public.oss-cn-shenzhen.aliyuncs.com/exampledir/src.jpg"]];
//    self.touImage=touImage;
//    
//    UIImageView *pickImage=[[UIImageView alloc]init];
//    pickImage.frame=CGRectMake(_window_width*0.554, _window_width*0.448, _window_width*0.064, _window_width*0.064);
//    pickImage.image=[UIImage imageNamed:@"pickImage"];
//    [self.view addSubview:pickImage];
//    touImage.contentMode=UIViewContentModeScaleAspectFill;
//    
//    touImage.userInteractionEnabled=YES;
//    pickImage.userInteractionEnabled=YES;
//    UITapGestureRecognizer *Tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Gesture1)];
//    [touImage addGestureRecognizer:Tap1];
//    UITapGestureRecognizer *Tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Gesture2)];
//    [pickImage addGestureRecognizer:Tap2];
    
    
    UIView *boyView=[[UIView alloc]init];
    boyView.frame=CGRectMake(28*KWidthScale, _window_width*0.6, 140*KWidthScale, 186*KWidthScale);
//    boyView.backgroundColor=[UIColor grayColor];
    boyView.userInteractionEnabled=YES;
    [self.view addSubview:boyView];
    
    UIImageView *boyImage=[[UIImageView alloc]init];
    boyImage.frame=CGRectMake(0,0, boyView.frame.size.width, boyView.frame.size.width);
    boyImage.image=[UIImage imageNamed:@"基本信息默认男"];
    [boyView addSubview:boyImage];
    
    boyImage.layer.masksToBounds = YES;
    boyImage.layer.cornerRadius = 20*KWidthScale;
    boyImage.layer.borderWidth = 2;
    boyImage.layer.borderColor = [UIColor colorWithHex:0x2B56FB].CGColor;
    self.boyImageView=boyImage;
    
    UILabel *boyLab=[[UILabel alloc]init];
    boyLab.frame = CGRectMake(0, boyImage.frame.origin.y+boyImage.frame.size.height+12*KWidthScale,boyView.frame.size.width,22*KWidthScale);
    boyLab.text=@"男";
    boyLab.textColor=[UIColor colorWithHex:0x2B56FB];
    boyLab.textAlignment=NSTextAlignmentCenter;
    boyLab.font=[UIFont systemFontOfSize:16];
    [boyView addSubview:boyLab];
    self.boyLab=boyLab;
    
  
    
    UIView *girlView=[[UIView alloc]init];
    girlView.frame=CGRectMake(208*KWidthScale, _window_width*0.6, 140*KWidthScale, 186*KWidthScale);
//    girlView.backgroundColor=[UIColor grayColor];
    girlView.userInteractionEnabled=YES;
    [self.view addSubview:girlView];
    
    UITapGestureRecognizer *boytap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(boyViewGesture)];
    [boyView addGestureRecognizer:boytap];
    
    UITapGestureRecognizer *girltap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(girlViewGesture)];
    [girlView addGestureRecognizer:girltap];
    
    
    UIImageView *girlImage=[[UIImageView alloc]init];
    girlImage.frame=CGRectMake(0,0, girlView.frame.size.width, girlView.frame.size.width);
    girlImage.image=[UIImage imageNamed:@"基本信息默认女"];
    [girlView addSubview:girlImage];
    
    girlImage.layer.masksToBounds = YES;
    girlImage.layer.cornerRadius = 20*KWidthScale;
    girlImage.layer.borderWidth = 0;
    girlImage.layer.borderColor = [UIColor colorWithHex:0xFF729A].CGColor;
    self.girlImageView=girlImage;
    
    
    UILabel *girlLab=[[UILabel alloc]init];
    girlLab.frame = CGRectMake(0, girlImage.frame.origin.y+girlImage.frame.size.height+12*KWidthScale,girlImage.frame.size.width,22*KWidthScale);
    girlLab.text=@"女";
    girlLab.textColor=[UIColor colorWithHex:0xFF729A];
    girlLab.textAlignment=NSTextAlignmentCenter;
    girlLab.font=[UIFont systemFontOfSize:16];
    [girlView addSubview:girlLab];
    girlLab.textColor=[UIColor colorWithHex:0x999999];
    self.girlLab=girlLab;
    
    
    //昵称
    UIView *nickNameView=[[UIView alloc]init];
    nickNameView.frame=CGRectMake(_window_width*0.085, boyView.frame.origin.y+boyView.frame.size.height+44*KWidthScale, _window_width*0.829, _window_width*0.0746);
//    nickNameView.backgroundColor=[UIColor blueColor];
    [self.view addSubview:nickNameView];
    
    
    UILabel *nicknameLab=[[UILabel alloc]init];
    nicknameLab.frame=CGRectMake(0, 0, nickNameView.frame.size.width*0.14, nickNameView.frame.size.height*0.857);
    nicknameLab.text=@"昵称";
    nicknameLab.textColor=[UIColor colorWithHex:0x999999];
    nicknameLab.font=[UIFont systemFontOfSize:14];
    [nickNameView addSubview:nicknameLab];
    
    UIView *nicknameLine=[[UIView alloc]init];
    nicknameLine.frame=CGRectMake(0, nickNameView.frame.size.height, nickNameView.frame.size.width, 0.5);
    nicknameLine.backgroundColor=[UIColor colorWithHex:0xE6E6E6];
    [nickNameView addSubview:nicknameLine];
    
  
    UITextField *textField1 = [[UITextField alloc]init];
    textField1.frame=CGRectMake(nickNameView.frame.size.width*0.14, 0, nickNameView.frame.size.width*0.762, nickNameView.frame.size.height*0.857);
//        textField1.backgroundColor = [UIColor orangeColor];
    textField1.font = [UIFont systemFontOfSize:16.0f];
    textField1.textAlignment = NSTextAlignmentLeft;
    textField1.textColor=[UIColor colorWithHex:0x3C3C3C];
    textField1.delegate=self;
    textField1.placeholder=@"请输入昵称";
    [nickNameView addSubview:textField1];
    
    self.nickNameField=textField1;
    
    
    UIButton *suijiNameBtn=[[UIButton alloc]init];
    suijiNameBtn.frame = CGRectMake(nickNameView.frame.size.width*0.90, 0, 30,nickNameView.frame.size.height*0.857);
    [suijiNameBtn addTarget:self action:@selector(suijiNameBtnAction) forControlEvents:UIControlEventTouchUpInside];
//    [otherLoginBtn setBackgroundColor:[UIColor colorWithHex:0xFF2742]];
//    otherLoginBtn.layer.masksToBounds = YES;
//    otherLoginBtn.layer.cornerRadius = otherLoginBtn.frame.size.height/2;
//    otherLoginBtn.layer.borderWidth = 1;
//    otherLoginBtn.layer.borderColor = [UIColor colorWithHex:0xD9D9D9].CGColor;
    [suijiNameBtn setTitle:@"随机" forState:UIControlStateNormal];
    [suijiNameBtn setTitleColor:[UIColor colorWithHex:0xFF729A] forState:UIControlStateNormal];
    suijiNameBtn.titleLabel.font = [UIFont systemFontOfSize:14];
//    [suijiNameBtn setBackgroundColor:[UIColor colorWithHex:0xFF729A]];
    
//    [suijiNameBtn setImage:[UIImage imageNamed:@"SaiZi"] forState:UIControlStateNormal];
//    [nickNameView addSubview:suijiNameBtn];
    self.suijiNameBtn=suijiNameBtn;
    
    
    
    //生日
    UIView *birthView=[[UIView alloc]init];
    birthView.frame=CGRectMake(_window_width*0.085, nickNameView.frame.origin.y+nickNameView.frame.size.height+20*KWidthScale, _window_width*0.829, _window_width*0.0746);
//    birthView.backgroundColor=[UIColor blueColor];
    [self.view addSubview:birthView];
    
    UILabel *birthLab=[[UILabel alloc]init];
    birthLab.frame=CGRectMake(0, 0, birthView.frame.size.width*0.14, birthView.frame.size.height*0.857);
    birthLab.text=@"生日";
    birthLab.textColor=[UIColor colorWithHex:0x999999];
    birthLab.font=[UIFont systemFontOfSize:14];
    [birthView addSubview:birthLab];
    
    UIView *birthLine=[[UIView alloc]init];
    birthLine.frame=CGRectMake(0, birthView.frame.size.height, birthView.frame.size.width, 0.5);
    birthLine.backgroundColor=[UIColor colorWithHex:0xE6E6E6];
    [birthView addSubview:birthLine];
    
    
    self.birthLab=[[UILabel alloc]init];
    self.birthLab.frame=CGRectMake(birthView.frame.size.width*0.14, 0, birthView.frame.size.width*0.762, birthView.frame.size.height*0.857);
    self.birthLab.text=@"选择生日";
    
//    self.birthLab.text=self.boyBirth;
    self.birthLab.textColor=[UIColor colorWithHex:0xD1D4D8];
//    self.birthLab.textColor=[UIColor blackColor];
    self.birthLab.font=[UIFont systemFontOfSize:16];
//    self.birthLab.backgroundColor=[UIColor orangeColor];
    [birthView addSubview:self.birthLab];
    
    self.birthLab.userInteractionEnabled=YES;
    UITapGestureRecognizer *Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Gesture:)];
    [self.birthLab addGestureRecognizer:Tap];
    
   
    
#if 0

    UIView *sexView=[[UIView alloc]init];
    sexView.frame=CGRectMake(_window_width*0.085, _window_width*0.912, _window_width*0.829, _window_width*0.096);
//    sexView.backgroundColor=[UIColor blueColor];
    [self.view addSubview:sexView];
    
    
    UILabel *sexLab=[[UILabel alloc]init];
    sexLab.frame=CGRectMake(0, 0, sexView.frame.size.width*0.14, sexView.frame.size.height*0.857);
    sexLab.text=@"性别";
    sexLab.font=[UIFont systemFontOfSize:16];
    [sexView addSubview:sexLab];
    
    
    
    
    
    UIButton *otherLoginBtn=[[UIButton alloc]init];
    otherLoginBtn.frame = CGRectMake(sexView.frame.size.width*0.14, 0, sexView.frame.size.width*0.398,sexView.frame.size.width*0.398*0.29);
    otherLoginBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [otherLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [otherLoginBtn addTarget:self action:@selector(boyBtnAction) forControlEvents:UIControlEventTouchUpInside];
//    [otherLoginBtn setBackgroundColor:[UIColor colorWithHex:0xFF2742]];
//    otherLoginBtn.layer.masksToBounds = YES;
//    otherLoginBtn.layer.cornerRadius = otherLoginBtn.frame.size.height/2;
//    otherLoginBtn.layer.borderWidth = 1;
//    otherLoginBtn.layer.borderColor = [UIColor colorWithHex:0xD9D9D9].CGColor;
    [sexView addSubview:otherLoginBtn];
    
    
    [otherLoginBtn setBackgroundColor:[UIColor colorWithHex:0xFE1C52]];
    otherLoginBtn.layer.masksToBounds = YES;
    otherLoginBtn.layer.cornerRadius = otherLoginBtn.frame.size.height/2;
    [otherLoginBtn setImage:[UIImage imageNamed:@"boySex_big"] forState:UIControlStateNormal];
    [otherLoginBtn setTitle:@"  男生" forState:UIControlStateNormal];
    
    
    self.boyBtn=otherLoginBtn;
    
    
    
    
    self.girlBtn=[[UIButton alloc]init];
    self.girlBtn.frame = CGRectMake(sexView.frame.size.width*0.60, 0, sexView.frame.size.width*0.398,sexView.frame.size.width*0.398*0.29);
    self.girlBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.girlBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.girlBtn addTarget:self action:@selector(girlBtnAction) forControlEvents:UIControlEventTouchUpInside];
//    [otherLoginBtn setBackgroundColor:[UIColor colorWithHex:0xFF2742]];
//    otherLoginBtn.layer.masksToBounds = YES;
//    otherLoginBtn.layer.cornerRadius = otherLoginBtn.frame.size.height/2;
//    otherLoginBtn.layer.borderWidth = 1;
//    otherLoginBtn.layer.borderColor = [UIColor colorWithHex:0xD9D9D9].CGColor;
    [sexView addSubview:self.girlBtn];
    
    
    [self.girlBtn setBackgroundColor:[UIColor colorWithHex:0xD1D4D8]];
    self.girlBtn.layer.masksToBounds = YES;
    self.girlBtn.layer.cornerRadius = otherLoginBtn.frame.size.height/2;
    [self.girlBtn setImage:[UIImage imageNamed:@"girlSex_big"] forState:UIControlStateNormal];
    [self.girlBtn setTitle:@"  女生" forState:UIControlStateNormal];
    
#endif
    
    //邀请码
    UIView *yaoqingView=[[UIView alloc]init];
//    yaoqingView.frame=CGRectMake(_window_width*0.085, _window_width*1.07, _window_width*0.829, _window_width*0.0746);
    yaoqingView.frame=CGRectMake(_window_width*0.085, birthView.frame.origin.y+birthView.frame.size.height+40*KWidthScale, _window_width*0.829, _window_width*0.786*0.169);
    yaoqingView.backgroundColor=[UIColor colorWithHex:0xF9F9F9];
    [self.view addSubview:yaoqingView];
    
    yaoqingView.layer.masksToBounds = YES;
    yaoqingView.layer.cornerRadius = yaoqingView.frame.size.height/2;
    yaoqingView.layer.borderWidth = 1;
    yaoqingView.layer.borderColor = [UIColor colorWithHex:0xE9EBED].CGColor;
    
    
    self.yaoqingTF = [[UITextField alloc]init];
    self.yaoqingTF.frame=CGRectMake(20, 0, yaoqingView.frame.size.width-40, yaoqingView.frame.size.height*0.857);
//        textField1.backgroundColor = [UIColor orangeColor];
    self.yaoqingTF.font = [UIFont systemFontOfSize:16.0f];
    self.yaoqingTF.textAlignment = NSTextAlignmentLeft;
    self.yaoqingTF.textColor=[UIColor colorWithHex:0x3C3C3C];
    self.yaoqingTF.delegate=self;
    self.yaoqingTF.placeholder=@"请输入邀请码（非必填）";
    NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:@"请输入邀请码（非必填）"];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.alignment = NSTextAlignmentCenter;
    [placeholder addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, placeholder.length)];
    self.yaoqingTF.attributedPlaceholder = placeholder;
    [yaoqingView addSubview:self.yaoqingTF];
    
    
    
    
    
    
    //手机号码登录
    UIButton *oneLoginBtn=[[UIButton alloc]init];
//    oneLoginBtn.frame = CGRectMake( _window_width*0.106, _window_width*1.26, _window_width*0.786,_window_width*0.786*0.169);
    oneLoginBtn.frame=CGRectMake(_window_width*0.085, yaoqingView.frame.origin.y+yaoqingView.frame.size.height+40*KWidthScale, _window_width*0.829, _window_width*0.786*0.169);
    [oneLoginBtn setTitle:@"保存" forState:UIControlStateNormal];
    oneLoginBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    [oneLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [oneLoginBtn addTarget:self action:@selector(submitAction) forControlEvents:UIControlEventTouchUpInside];
    [oneLoginBtn setBackgroundColor:[UIColor colorWithHex:0xFE1C52]];
    
    oneLoginBtn.layer.masksToBounds = YES;
    oneLoginBtn.layer.cornerRadius = oneLoginBtn.frame.size.height/2;
    [self.view addSubview:oneLoginBtn];
//    oneLoginBtn.enabled=NO;
    [oneLoginBtn setBackgroundColor:[UIColor colorWithHex:0xFF729A]];
    self.submitBtn=oneLoginBtn;
    
   
//    if (saveSystemConfig!=nil) {
//        int is_examine=[saveSystemConfig[@"is_examine"] intValue];
//        if (is_examine==1) {
//            yaoqingView.hidden=YES;
//        }
//    }
    yaoqingView.hidden=YES;
}
-(void)backBtnAction{
//    [self.navigationController popViewControllerAnimated:YES];
    
//    [self dismissViewControllerAnimated:YES completion:^{
//        
//    }];
//    return;
    
    self.tipViewType=1;
//    CPTipView *view =[[CPTipView alloc]initCPTipViewWithContent:@"还差一步即可完成个人资料\n把握缘分，早日脱单哦～" title:@"温馨提示" confirmStr:@"继续填写" cancelStr:@"返回修改" buttonCount:1];
//    view.delegate=self;
//    [view show];
}
//提交
-(void)submitAction{
    if(self.sex==0){
//        [self addTipView];
        [self loadComplete];
    }else{
        [self loadComplete];
    }
}

-(void)btnClickedIndex:(int)index{
    NSLog(@"%d",index);
    if(index==1){
        if (self.tipViewType==2) {
            if (self.wxLogin==1) {//登录进来---去绑定手机号
                [self pushBDSJ];
            }else{
                [self loadComplete];
            }
        }
    }
}
-(void)pushBDSJ{
    
    NSString *sex=@"2";
    NSString *icon=self.girluploadImageUrl;
    NSString *nickname=self.girlNickName;
    NSString *birthday=self.girlBirth;
    
//    CPChangePhoneNumVC *vc=[[CPChangePhoneNumVC alloc]init];
//    vc.icon=icon;
//    vc.sex=sex;
//    vc.nickname=nickname;
//    vc.birthday=birthday;
//    vc.user_code=self.yaoqingTF.text!=nil?self.yaoqingTF.text:@"";
//    vc.wxcode=self.wxcode;
//    vc.wxLogin=self.wxLogin;
//    [self.navigationController pushViewController:vc animated:YES];
}
-(void)boyBtnAction{
    self.sex=1;
    self.suijiNameBtn.hidden=NO;
    [self.boyBtn setBackgroundColor:[UIColor colorWithHex:0xFE1C52]];
    [self.girlBtn setBackgroundColor:[UIColor colorWithHex:0xD1D4D8]];
    
    if(self.boyImage==nil){
        self.touImage.image=[UIImage imageNamed:@"manHead"];
    }else{
        self.touImage.image=self.boyImage;
    }
   
    if(![self.boyBirth isEqualToString:@"选择生日"]&&self.boyBirth!=nil){
        self.birthLab.text=self.boyBirth;
        self.birthLab.textColor=[UIColor blackColor];
    }else{
        self.birthLab.text=@"选择生日";
        self.birthLab.textColor=[UIColor colorWithHex:0xD1D4D8];
    }
    
    self.nickNameField.text=self.boyNickName;
    self.imageData=self.boyImageData;
    
    
    [self PerfectChangeBtnBackground];
}
-(void)girlBtnAction{
    self.sex=0;
    self.suijiNameBtn.hidden=YES;
    [self.boyBtn setBackgroundColor:[UIColor colorWithHex:0xD1D4D8]];
    [self.girlBtn setBackgroundColor:[UIColor colorWithHex:0xFE1C52]];
    if(self.girlImage==nil){
        self.touImage.image=[UIImage imageNamed:@"upImage"];
    }else{
        self.touImage.image=self.girlImage;
    }
    
    
    if(![self.girlBirth isEqualToString:@"选择生日"]&&self.girlBirth!=nil){
        self.birthLab.text=self.girlBirth;
        self.birthLab.textColor=[UIColor blackColor];
    }else{
        self.birthLab.text=@"选择生日";
        self.birthLab.textColor=[UIColor colorWithHex:0xD1D4D8];
    }
    self.nickNameField.text=self.girlNickName;
    self.imageData=self.girlImageData;
    
    [self PerfectChangeBtnBackground];
    
}
-(void)suijiNameBtnAction{
    [self loadRandNickname];
   
}
-(void)Gesture:(UITapGestureRecognizer*)tap
{
    [self.nickNameField resignFirstResponder];
    [self.yaoqingTF resignFirstResponder];
    
//    self.aview.frame=CGRectMake(-10, 0, 55,_window_height-216-44);
    
    
    NSDate *now = [NSDate date];
    NSLog(@"now date is: %@", now);
        
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
     
    int year = [dateComponent year];
    int month = [dateComponent month];
    int day = [dateComponent day];
    
   

    
    // 出生年月日
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
    datePickerView.pickerMode = BRDatePickerModeYMD;
    datePickerView.title = @"选择生日";
    datePickerView.selectDate = self.birthdaySelectDate;
    datePickerView.selectValue = self.birthStr;
    datePickerView.minDate = [NSDate br_setYear:1940 month:10 day:1];
    datePickerView.maxDate = [NSDate br_setYear:year month:month day:day];
    datePickerView.isAutoSelect = YES;
//            datePickerView.addCustomString = @"自定义";
    // 指定不可选择的日期
    //datePickerView.nonSelectableDates = @[[NSDate br_setYear:2020 month:7 day:25], [NSDate br_setYear:2020 month:8 day:26]];
    datePickerView.keyView = self.view; // 将组件 datePickerView 添加到 self.view 上，默认是添加到 keyWindow 上
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        self.birthLab.text=selectValue;
        self.birthLab.textColor=[UIColor blackColor];
//        self.birthLab2.hidden=YES;
        [self PerfectChangeBtnBackground];
        self.birthdaySelectDate = selectDate;
        self.birthStr=selectValue;
        NSLog(@"selectValue=%@", selectValue);
        NSLog(@"selectDate=%@", selectDate);
        NSLog(@"---------------------------------");
        
    };
    datePickerView.cancelBlock = ^{
//        self.aview.frame=CGRectMake(-10, 0, 55,_window_height);
    };
    
    
    // 设置年份背景
    UILabel *yearLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 44, self.view.bounds.size.width, 216)];
    yearLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    yearLabel.backgroundColor = [UIColor clearColor];
    yearLabel.textAlignment = NSTextAlignmentCenter;
    yearLabel.textColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.2f];
    yearLabel.font = [UIFont boldSystemFontOfSize:100.0f];
//    NSString *yearString = self.birthdaySelectDate ? @(self.birthdaySelectDate.br_year).stringValue : @([NSDate date].br_year).stringValue;
//    if (self.infoModel.birthdayStr && [self.infoModel.birthdayStr isEqualToString:@"自定义"]) {
//        yearString = @"";
//    }
//            yearLabel.text = yearString;
    yearLabel.text = @"";
    [datePickerView.alertView addSubview:yearLabel];
    
    BRPickerStyle *customStyle = [[BRPickerStyle alloc]init];
    customStyle.pickerColor = [UIColor clearColor];
    customStyle.selectRowTextColor = [UIColor blueColor];
    datePickerView.pickerStyle = customStyle;
    [datePickerView show];
   
}
-(void)PerfectChangeBtnBackground{
    
//    if ([[self.textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]length] == 0) {
//        [self showSVProgressHUDStr:@"昵称不能为空"];
//        return;
//    }
//    if (self.ninknameStr==nil||[self.ninknameStr isEqualToString:@""]) {
//        [self showSVProgressHUDStr:@"昵称不能为空"];
//        return;
//    }
    
    return;
    
    self.nickNameField.text=[self.nickNameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if(self.sex==1){
        
        
        self.boyNickName=self.nickNameField.text;
        self.boyBirth=self.birthLab.text;
        self.boyImageData=self.imageData;
        
        
        if (self.boyNickName.length>0&&![self.boyBirth isEqualToString:@"选择生日"]) {
            [self.submitBtn setBackgroundColor:[UIColor colorWithHex:0xFE1C52]];
            self.submitBtn.enabled=YES;
        }else{
            [self.submitBtn setBackgroundColor:[UIColor colorWithHex:0xD1D4D8]];
            self.submitBtn.enabled=NO;
        }
        
    }else{
        
        self.girlNickName=self.nickNameField.text;
        self.girlBirth=self.birthLab.text;
        self.girlImageData=self.imageData;
        
        
        if (self.girlNickName.length>0&&![self.girlBirth isEqualToString:@"选择生日"]&&self.girluploadImageUrl!=nil&&![self.girluploadImageUrl isEqualToString:@""]) {
            [self.submitBtn setBackgroundColor:[UIColor colorWithHex:0xFE1C52]];
            self.submitBtn.enabled=YES;
        }else{
            [self.submitBtn setBackgroundColor:[UIColor colorWithHex:0xD1D4D8]];
            self.submitBtn.enabled=NO;
        }
    }
    
}
-(void)Gesture1{
    [self pickHeadView];
}
-(void)Gesture2{
    [self takePhoto];
    
   
}
-(void)pickHeadView{
    
    [self.nickNameField resignFirstResponder];
    [self.yaoqingTF resignFirstResponder];
    
    NSLog(@"选择头像");
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    //设置代理
    imagePickerController.delegate = self;
    imagePickerController.allowsEditing = YES;
    
    //直接调用系统相册
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.modalPresentationStyle = 0;
    [self presentViewController:imagePickerController animated:YES completion:nil];
}
-(void)takePhoto{
//    [self.nickNameField resignFirstResponder];
//    [self.yaoqingTF resignFirstResponder];
//    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
//        
//        
//        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];//初始化
//        [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
//        imagePickerController.cameraCaptureMode =UIImagePickerControllerCameraCaptureModePhoto;
////            imagePicker.showsCameraControls = NO;
//        imagePickerController.delegate = self;
//        imagePickerController.allowsEditing = YES;
//        [self presentViewController:imagePickerController animated:YES completion:nil];
//       
//    }
//    else {
//
//        UIAlertController *alerController = [UIAlertController alertControllerWithTitle:@"提示" message:@"当前设备不支持拍照。" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//            
//            
//        }];
//        [alerController addAction:cancelAction];
//        
//        [self presentViewController:alerController animated:YES completion:^{
//            
//        }];
//    }
    
    MSCTakePictureViewController *faceVC = [[MSCTakePictureViewController alloc]init];
    faceVC.takePictureType = MSCTakePictureTypePhoto;
    faceVC.isShowChangeCameraBtn=YES;
    faceVC.block = ^(BOOL isFinished, NSData *imageData, UIImage *image){
        if (isFinished)
        {
            NSData *data;
            if (UIImagePNGRepresentation(image) == nil) {
                data = UIImageJPEGRepresentation(image, 1.0);
            } else {
                data = UIImagePNGRepresentation(image);
            }
            self.touImage.image=image;
    //        self.dataStr=[NSString stringWithFormat:@"%@",data];
            self.imageData=data;

            if(self.sex==1){
                self.boyImage=image;
            }else{
                self.girlImage=image;
            }
            [self PerfectChangeBtnBackground];
            
            [self saveImage:image withName:@"currentImage"];
        }
    };
    
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:faceVC];
    nav.modalPresentationStyle=0;
    [self presentViewController:nav animated:YES completion:nil];
}
- (void)saveImage:(UIImage *)currentImage withName:(NSString *)imageName {
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
    [imageData writeToFile:fullPath atomically:NO];
    uploadFilePath = fullPath;
    NSLog(@"uploadFilePath : %@", uploadFilePath);
    
    if (self.sex==1) {
        self.boyuploadFilePath=fullPath;
    }else{
        self.girluploadFilePath=fullPath;
    }
    
//    NSString *funcStr = @"普通上传";
//    NSString * objectKey = @"exampledir/src.jpg";
//    [self.oss asyncPutImage:objectKey localFilePath:uploadFilePath success:^(id result) {
//        [self showMessage:funcStr inputMessage:@"success"];
//    } failure:^(NSError *error) {
//        [self showMessage:funcStr inputMessage:error.localizedDescription];
//    }];
    
    [self loadputImageToken];
}


- (void)showMessage:(NSString *)putType
       inputMessage:(NSString*)message {
    UIAlertAction * defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:putType message:message preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
}

#pragma mark - 选择图片完成的时候调用
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    if ([type isEqualToString:@"public.image"]) {
        //先把图片转成NSData
        UIImage* image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
        NSData *data;
        if (UIImagePNGRepresentation(image) == nil) {
            data = UIImageJPEGRepresentation(image, 1.0);
        } else {
            data = UIImagePNGRepresentation(image);
        }
        self.touImage.image=image;
//        self.dataStr=[NSString stringWithFormat:@"%@",data];
        self.imageData=data;

        if(self.sex==1){
            self.boyImage=image;
        }else{
            self.girlImage=image;
        }
        [self PerfectChangeBtnBackground];
        
    }
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSLog(@"image width:%f, height:%f", image.size.width, image.size.height);
    [self saveImage:image withName:@"currentImage"];
    
//#if !DEBUG
//
//    if ([CPGetProxyStatus getProxyStatus]) {//开了代理
//        return;
//    }
//
//#endif
//
//    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
//    if ([type isEqualToString:@"public.image"]) {
//        //先把图片转成NSData
//        UIImage* image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
//        NSData *data;
//        if (UIImagePNGRepresentation(image) == nil) {
//            data = UIImageJPEGRepresentation(image, 1.0);
//        } else {
//            data = UIImagePNGRepresentation(image);
//        }
//        //        self.headImg.image=image;
////        self.dataStr=[NSString stringWithFormat:@"%@",data];
////        self.imageData=data;
////        [self PerfectChangeBtnBackground];
//
//
//        //        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
////        NSString *uid = [NSString stringWithFormat:@"%d",arc4random()%10000 + 20000];
//        NSString *uid = [Config getAccess_uid];
//        NSString *str2=@"szxhc588598szxhc588598";
//        NSString *str3=[uid stringByAppendingString:str2];
//        NSString *md5=[self md5:str3];
//        NSLog(@"%@",md5);
//
//        AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
//        AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];
//        [requestSerializer setValue:md5 forHTTPHeaderField:@"aops"];
//        [requestSerializer setValue:uid forHTTPHeaderField:@"access_uid"];
//        NSString *access_token=@"";
//        if ([Config getAccess_token]!=nil) {
//            access_token=[Config getAccess_token];
//        }
//        [requestSerializer setValue:access_token forHTTPHeaderField:@"access_token"];
//        session.requestSerializer = requestSerializer;
//        //        NSString *userBaseUrl = [purl stringByAppendingFormat:@"common/upload"];
//        NSString *userBaseUrl =uploadImageUrl;
//        [session POST:userBaseUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
//            if (image) {
//                [formData appendPartWithFileData:[Utils compressImage:image] name:@"file" fileName:@"duibinaf.png" mimeType:@"image/jpeg"];
//            }
//        } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//            NSLog(@"%@",responseObject);
//            NSNumber *number = [responseObject valueForKey:@"code"];
//
//            if([number isEqualToNumber:[NSNumber numberWithInt:0]])
//            {
//                [self.imageUrlArray addObject:[responseObject valueForKey:@"data"][0]];
//
////                self.addPhotoBtn.hidden=YES;
////                self.touImage.userInteractionEnabled=NO;
//                //                self.headImg.image=image;
//
//                [self HUDMsg:@"头像上传成功！"];
//                [self PerfectChangeBtnBackground];
//            }
//            else
//            {
////                [MBProgressHUD showError:[responseObject valueForKey:@"msg"]];
//                [self HUDMsg:[responseObject valueForKey:@"msg"]];
//            }
//
//        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//            [MBProgressHUD hideHUDForView:self.view];
//            [MBProgressHUD showError:@"网络错误"];
//        }];
//
//        [picker dismissViewControllerAnimated:YES completion:nil];
//
//    }
}
-(void)addTipView{
    self.tipViewType=2;
    PUTipView *view =[[PUTipView alloc]initCPTipViewWithContent:@"您当前选择的性别为：女 \n确认后不可更改，是否确认注册？" title:@"温馨提示" confirmStr:@"确定注册" cancelStr:@"返回修改" buttonCount:2];
    view.delegate=self;
    [view show];
}

-(void)loadRandNickname{
    
    return;
   
    NSDictionary *param =@{
//                            @"ids":str,
//                            @"type":@"text",
                          };
    NSString *path=@"/user/nickname";
    NSString *url = [NSString stringWithFormat:@"%@%@",baseUrl,path];
    [[AFNetManager shareManager] postDataWithURLString:url path:path parameters:param success:^(NSURLResponse *operation, id successObject) {
        
        NSLog(@"%@",successObject);
//        NSString *dataStr= successObject[@"data"];
        NSString *result=successObject[@"result"];
        NSString *nickname=@"";
        NSString *ID=@"";
        if ([successObject[@"result"] isKindOfClass:[NSString class]]) {
            //解密Base64编码的字符串
            NSString *decryptedString = [AES128 decryptString:result key:dataKey iv:dataIv];
            NSDictionary *dic=[AES128 dictionaryWithJsonString:decryptedString];
            NSLog(@"json解析===%@",dic);
            nickname=dic[@"nickname"];
            ID=dic[@"id"];
            NSLog(@"昵称-----%@",nickname);
            self.ID=ID;
            self.nickname=nickname;
        }
        if ([successObject[@"code"] integerValue] == 200||[successObject[@"code"] integerValue] == 0) {
            NSString *dataStr= successObject[@"data"];
            self.boyNickName=nickname;
            if (self.sex==1) {
                self.nickNameField.text=self.boyNickName;
            }
            
            [self PerfectChangeBtnBackground];
        }else{
            [self showSVProgressHUDStr:successObject[@"message"]];
        }
        
    } failure:^(NSError *error) {
        NSLog(@"错误：%@",error);
    }];
}
-(void)loadComplete{
    
    self.nickNameField.text=[self.nickNameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if(self.sex==1){
        
        
        self.boyNickName=self.nickNameField.text;
        self.boyBirth=self.birthLab.text;
        self.boyImageData=self.imageData;
        
        
        if (self.boyNickName.length>0&&![self.boyBirth isEqualToString:@"选择生日"]) {
            [self.submitBtn setBackgroundColor:[UIColor colorWithHex:0xFE1C52]];
            self.submitBtn.enabled=YES;
        }else{
//            [self.submitBtn setBackgroundColor:[UIColor colorWithHex:0xD1D4D8]];
//            self.submitBtn.enabled=NO;
            
            [self showSVProgressHUDStr:@"请填写基本资料"];
            return;
        }
        
    }else{
        
        self.girlNickName=self.nickNameField.text;
        self.girlBirth=self.birthLab.text;
        self.girlImageData=self.imageData;
        
        
        if (self.girlNickName.length>0&&![self.girlBirth isEqualToString:@"选择生日"]) {
            [self.submitBtn setBackgroundColor:[UIColor colorWithHex:0xFE1C52]];
            self.submitBtn.enabled=YES;
        }else{
//            [self.submitBtn setBackgroundColor:[UIColor colorWithHex:0xD1D4D8]];
//            self.submitBtn.enabled=NO;
            
            [self showSVProgressHUDStr:@"请填写基本资料"];
            return;
        }
    }
  
    
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD show ];
    [SVProgressHUD showWithStatus:@"正在加载中，请稍后..."];
    
    NSString *sex=@"";
    NSString *icon=@"";
    NSString *nickname=@"";
    NSString *birthday=@"";
    NSString *fileName=@"";
    NSString *ID=@"";
    
    
    if (self.sex==1) {//男
        icon=self.boyuploadImageUrl;
        sex=@"2";
        nickname=self.boyNickName;
        birthday=self.boyBirth;
        fileName=self.boyupfileName;
        
        if ([nickname isEqualToString:self.nickname]) {
            ID=self.ID;
            ID=[NSString stringWithFormat:@"%@",ID];
        }else{
            ID=0;
        }
        
    }else{
        icon=self.girluploadImageUrl;
        sex=@"3";
        nickname=self.girlNickName;
        birthday=self.girlBirth;
        fileName=self.girlupfileName;
        ID=0;
    }
    
    fileName=[NSString stringWithFormat:@"/%@",fileName];
//    NSString *url = [NSString stringWithFormat:@"%@/info/complete",userpurl];
    
    NSString *path=@"/user/init_edit";
    NSString *url = [NSString stringWithFormat:@"%@%@",baseUrl,path];
    NSDictionary *param = @{
                            @"id":@([ID intValue]),
                            @"nickname":nickname,
                            @"birthday":birthday,
                            @"sex":sex,
                            @"invite_code":self.yaoqingTF.text!=nil?self.yaoqingTF.text:@"",
                            @"sm_device_id":@"",
                            @"avatar":@"",
                            };
    //44129000272
    [[AFNetManager shareManager] postDataWithURLString:url path:path parameters:param success:^(NSURLResponse *operation, id successObject) {
        NSLog(@"%@",successObject);
        [SVProgressHUD dismiss];
        
        NSString *result=successObject[@"result"];
        if ([successObject[@"result"] isKindOfClass:[NSString class]]) {
            //解密Base64编码的字符串
            NSString *decryptedString = [AES128 decryptString:result key:dataKey iv:dataIv];
            NSDictionary *dic=[AES128 dictionaryWithJsonString:decryptedString];
            NSLog(@"json解析===%@",dic);
            NSString *code=dic[@"code"];
            NSLog(@"验证码-----%@",code);
        }
        if ([successObject[@"code"] integerValue] == 200) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"loginSuccessUpdataNotification" object:self userInfo:nil];
            [self loginYunXin];
            [self loadUserInfo];
            [self loadsystemconfig];
//            [self loadInfoMy];
//            [self loadAppInit];
            
            if(self.isFirst==1){
                [self dismissViewControllerAnimated:NO completion:nil];
                AppDelegate *appDelegate=[[UIApplication sharedApplication] delegate];
                [appDelegate addCPTabBarController];
            }else{
                [self dismissViewControllerAnimated:YES completion:nil];
            }
        } else {
            [self showSVProgressHUDStr:successObject[@"message"]];
        }
            
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss];
        NSLog(@"%@",error);
    }];
}


-(void)loadUserInfo{
    
    NSDictionary *param =@{
                        
                          };
    NSString *path=@"/user/info";
    NSString *url1 = [NSString stringWithFormat:@"%@%@",baseUrl,path];
    [[AFNetManager shareManager] postDataWithURLString:url1 path:path parameters:param success:^(NSURLResponse *operation, id successObject) {
        
        NSString *result=successObject[@"result"];
        NSDictionary *dic=@{};
        if ([successObject[@"result"] isKindOfClass:[NSString class]]) {
            //解密Base64编码的字符串
            NSString *decryptedString = [AES128 decryptString:result key:dataKey iv:dataIv];
            dic=[AES128 dictionaryWithJsonString:decryptedString];
            NSLog(@"json解析===%@",dic);
        }
        
        if ([successObject[@"code"] integerValue] == 200||[successObject[@"code"] integerValue] == 0) {
            LiveUser *userInfo = [[LiveUser alloc] initWithDic:dic];
            userInfo.token=[Config getToken];
            [Config saveProfile:userInfo];
        } else {
            [self showSVProgressHUDStr:successObject[@"message"]];
        }
        
    } failure:^(NSError *error) {
        NSLog(@"错误：%@",error);
    }];
    
}
//登录云信
-(void)loginYunXin{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"loginYunXinNSNotification" object:self userInfo:nil];
}
//aliyun_oss_my_user_sts
//aliyun_oss_blog_sts
//aliyun_oss_photo_sts
//aliyun_oss_public_sts
-(void)loadputImageToken{
    //    dispatch_sync(dispatch_get_main_queue(),^{
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD show ];
            [SVProgressHUD showWithStatus:@"正在加载中，请稍后..."];
    //    });
    
    
    NSString *url = [NSString stringWithFormat:@"%@/aliyun_oss_my_user_sts/",@""];
    [[AFNetManager shareManager] getDataWithURLString:url parameters:nil success:^(NSURLResponse *operation, id successObject) {
        NSLog(@"%@",successObject);
        if ([successObject[@"code"] integerValue] == 0) {
            NSDictionary *dic= successObject[@"data"];
            NSString *region_id=dic[@"region_id"];
            NSString *bucket=dic[@"bucket"];
            NSString *end_point=dic[@"end_point"];
            NSString *SecurityToken=dic[@"credentials"][@"SecurityToken"];
            NSString *AccessKeySecret=dic[@"credentials"][@"AccessKeySecret"];
            NSString *AccessKeyId=dic[@"credentials"][@"AccessKeyId"];
            NSString *Expiration=dic[@"credentials"][@"Expiration"];
            [self uploadRegion_id:region_id bucket:bucket end_point:end_point SecurityToken:SecurityToken AccessKeySecret:AccessKeySecret AccessKeyId:AccessKeyId Expiration:Expiration];
        }else{
            [SVProgressHUD dismiss ];
            [self showSVProgressHUDStr:successObject[@"message"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss ];
        NSLog(@"%@",error);
    }];
}

//code = 0,
//message = "success",
//data =     {
//    region_id = "cn-shenzhen",
//    bucket = "huayuoss-public",
//    end_point = "oss-cn-shenzhen.aliyuncs.com",
//    credentials =     {
//        SecurityToken = "CAISxQJ1q6Ft5B2yfSjIr5bNHdLeg7ts1a+KO0/5o1gGSMRgqPfNmjz2IHhMenJqBu8ctf4xlW9Z7PoSlqZzVpZUWEvfdvxo855T8Aj5uhpaZlHsv9I+k5SANTW5KXyShb3/AYjQSNfaZY3eCTTtnTNyxr3XbCirW0ffX7SClZ9gaKZ8PGD6F00kYu1bPQx/ssQXGGLMPPK2SH7Qj3HXEVBjt3gX6wo9y9zmnpzHs0SD1g2jm7VJ+tuuGPX+MZkwZqUYesyuwel7epDG1CNt8BVQ/M909vccoWmc5I7CWQILvUTZYrCIoscNNgZ8YbMhAalAoeh1VnSBOERo/W6e6WGuXYk9O0y3LOgrcJvXth1u2PyN1KcplgUsw1H+12jPyXcAS1g1Wo3ElXQvRFG+p+ICxH+UVGHFnHKOVmOJL84huLjdpAorpz2AGoABh3v1RXL1DR2QixGCvAzigpzdaJFKQHqHHrMPpzCrQFDc28RirWvKgrIxru9SYK41cAFkVXPIc0hGtHzfM0DmJg+Egz4dKK1K6epGCAkvviiui5s14r0MqIV2I65cjccaPdgNXqH/t8/9eHbTGDdyAzEqRVF5TVRnnsnzNwQ+Xh4gAA==",
//        Expiration = "2024-05-08T05:46:17Z",
//        AccessKeySecret = "ohQnQzSXhXn4tJi5SnNMFnrptiLccTcBS3zB8QDjGtq",
//        AccessKeyId = "STS.NUxVhjndMbma9iHGXSDKLG2fx",
//    },
//},

//oss =     {
//    cdn =     {
//        public = "public-oss.zx520.net",
//        pl = "public-oss.zx520.net",
//        photo = "photo-oss.zx520.net",
//        blog = "blog-oss.zx520.net",
//        user = "user-oss.zx520.net",
//    },
//    cdn_scheme = "http://",
//},
-(void)uploadRegion_id:(NSString *)region_id bucket:(NSString *)bucket end_point:(NSString *)end_point SecurityToken:(NSString *)SecurityToken AccessKeySecret:(NSString *)AccessKeySecret AccessKeyId:(NSString *)AccessKeyId Expiration:(NSString*)Expiration{
    
}
- (NSString *)randStr {
    CFUUIDRef uuidObj = CFUUIDCreate(nil);
    CFStringRef uuidString = CFUUIDCreateString(nil, uuidObj);
    NSString *result = (NSString *)CFBridgingRelease(CFStringCreateCopy( NULL, uuidString));
    CFRelease(uuidObj);
    CFRelease(uuidString);
    return result;
}
-(void)loadAppInit{
    NSString *url = [NSString stringWithFormat:@"%@/app_init",@""];
    [[AFNetManager shareManager] getDataWithURLString:url parameters:nil success:^(NSURLResponse *operation, id successObject) {
        NSLog(@"%@",successObject);
//        NSString *dataStr= successObject[@"data"];
        if ([successObject[@"code"] integerValue] == 0) {
            NSString *dataStr= successObject[@"data"];
            
            NSDictionary *info_api = successObject[@"data"][@"intimacy_friend"];
            NSLog(@"%@",info_api);
            [Config saveIntimacy_friendInfo:info_api];
            
            NSDictionary *info_api1 = [Config getIntimacy_friend];
            NSLog(@"%@",info_api1);
           
        }else{
//            [self showSVProgressHUDStr:successObject[@"message"]];
        }
      
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
-(void)loadInfoMy{
    NSString *url = [NSString stringWithFormat:@"%@/info/my",@""];
    [[AFNetManager shareManager] getDataWithURLString:url parameters:nil success:^(NSURLResponse *operation, id successObject) {
        NSLog(@"%@",successObject);
//        NSString *dataStr= successObject[@"data"];
        if ([successObject[@"code"] integerValue] == 0) {
            
            LiveUser *userInfo = [[LiveUser alloc] initWithDic:successObject[@"data"]];
            [Config saveProfile2:userInfo];
            [self loadDetail];
        }else{
//            [self showSVProgressHUDStr:successObject[@"message"]];
        }
      
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
-(void)loadDetail{
    
    if ([[Config getSex] intValue]==1) {
        return;
    }
    if ([[Config getis_real] intValue]==1) {
        return;
    }
    
    NSString *user_id=[Config getUser_id];
    NSDictionary *param=@{
                          @"user_id":user_id,
                         };
    NSString *url = [NSString stringWithFormat:@"%@/info/detail",@""];
    [[AFNetManager shareManager] getDataWithURLString:url parameters:param success:^(NSURLResponse *operation, id successObject) {
        NSLog(@"%@",successObject);
        if ([successObject[@"code"] integerValue] == 0) {
            LiveUser *user =[Config myProfile];
            user.audit_icon = successObject[@"data"][@"audit_icon"];
            user.is_save_audit_icon = successObject[@"data"][@"is_save_audit_icon"];
            [Config updateProfile:user];
        }else{
            [self showSVProgressHUDStr:successObject[@"message"]];
        }
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
-(void)loadsystemconfig{

    NSDictionary *param =@{
                          };
    NSString *path=@"/system/config";
    NSString *url1 = [NSString stringWithFormat:@"%@%@",baseUrl,path];
    [[AFNetManager shareManager] postDataWithURLString:url1 path:path parameters:param success:^(NSURLResponse *operation, id successObject) {
        
        NSString *result=successObject[@"result"];
        NSDictionary *dic=@{};
        if ([successObject[@"result"] isKindOfClass:[NSString class]]) {
            //解密Base64编码的字符串
            NSString *decryptedString = [AES128 decryptString:result key:dataKey iv:dataIv];
            dic=[AES128 dictionaryWithJsonString:decryptedString];
            NSLog(@"json解析===%@",dic);
        }
        
        if ([successObject[@"code"] integerValue] == 200||[successObject[@"code"] integerValue] == 0) {
           
            
            NSDictionary *saveSystemConfig=dic;
            [Config saveSystemConfig:saveSystemConfig];
            NSDictionary *saveSystemConfig1 = [Config getSystemConfig];
            
        } else {
//            [self showSVProgressHUDStr:successObject[@"message"]];
        }
        
    } failure:^(NSError *error) {
        NSLog(@"错误：%@",error);
    }];
}
-(void)showSVProgressHUDStr:(NSString *)str{
    if ([str isKindOfClass:[NSNull class]]||str==nil||[str isEqualToString:@""]) {
        return;
    }
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:str];
}
@end
